package com.hursing.tractor.view;

import android.graphics.Rect;

import com.hursing.tractor.baseview.UIView;

public final class UIFlipPanelView extends UIView {

	private static int mLabelWidth;
	
	@Override
	public UIView layout(int w, int h) {
		final int top = (int) (h * 0.54);
		final int bottom = (int) (h * 0.63);
		final int buttonGap = (int) (w * 0.02);
		Rect panelFrame = new Rect(0, top, 0, bottom);
		int panelWidth = 0;
		// 前6个按钮是亮主按钮和暂停按钮
		for (int i = 0; i < 6; i++) {
			panelWidth += subviews().get(i).frame(new Rect(panelFrame)).measureWidth();
		}
		panelWidth += buttonGap * (subviews().size() - 1);
		
		// 设置panel大小，不管label
		panelFrame.left = (w - panelWidth) / 2;
		panelFrame.right = panelFrame.left + panelWidth;
		mFrame = panelFrame;
		
		int left = panelFrame.left;
		for (int i = 0; i < 6; i++) {
			UIView view = subviews().get(i);
			Rect frame = view.frame();
			frame.left = left;
			frame.right = left + view.measureWidth();
			left = frame.right + buttonGap;
		}
		
		sViews[VIEW_CONTINUE_BUTTON].frame(sViews[VIEW_PAUSE_BUTTON].frame());
		
		final int labelTop = (int) (h * 0.23);
		final int labelBottom = (int) (h * 0.29);
		sViews[VIEW_REMAINING_LABEL].frame(new Rect(0, labelTop, 0, labelBottom));
		sViews[VIEW_CURRENT_REMAINING_LABEL].frame(new Rect(0, labelTop, 0, labelBottom));
		if (mLabelWidth == 0) {
			mLabelWidth = sViews[VIEW_REMAINING_LABEL].measureWidth() + sViews[VIEW_CURRENT_REMAINING_LABEL].measureWidth();
		}
		sViews[VIEW_REMAINING_LABEL].frame().left = (w - mLabelWidth) / 2;
		sViews[VIEW_REMAINING_LABEL].frame().right = sViews[VIEW_REMAINING_LABEL].frame().left + sViews[VIEW_REMAINING_LABEL].measureWidth();
		sViews[VIEW_CURRENT_REMAINING_LABEL].frame().left = sViews[VIEW_REMAINING_LABEL].frame().right;
		sViews[VIEW_CURRENT_REMAINING_LABEL].frame().right = sViews[VIEW_CURRENT_REMAINING_LABEL].frame().left + sViews[VIEW_CURRENT_REMAINING_LABEL].measureWidth();
		return this;
	}

}
